package interview;

public class interview_03_01 {
    class TripleInOne {
        private final int STACK_SIZE;   //栈大小
        private int[] index;    //当前栈的栈顶指针
        private int[][] stack;  //栈

        public TripleInOne(int stackSize) {     //初始化操作
            this.STACK_SIZE=stackSize;
            this.index=new int[]{-1,-1,-1};
            this.stack=new int[3][STACK_SIZE];
        }

        public void push(int stackNum, int value) {
            if(index[stackNum]+1<STACK_SIZE){     //判断当前栈是否已满
                stack[stackNum][++index[stackNum]]=value;     //向栈内添加元素
            }
        }

        public int pop(int stackNum) {
            return isEmpty(stackNum)?-1:stack[stackNum][index[stackNum]--];
        }

        public int peek(int stackNum) {
            return isEmpty(stackNum)?-1:stack[stackNum][index[stackNum]];
        }

        public boolean isEmpty(int stackNum) {
            return index[stackNum]==-1;     //判断当前栈是否已空
        }
    }


/**
 * Your TripleInOne object will be instantiated and called as such:
 * TripleInOne obj = new TripleInOne(stackSize);
 * obj.push(stackNum,value);
 * int param_2 = obj.pop(stackNum);
 * int param_3 = obj.peek(stackNum);
 * boolean param_4 = obj.isEmpty(stackNum);
 */
}
